package net.thellium.blipocentric.client;

import net.thellium.blipocentric.client.services.BlipClientService;
import net.thellium.blipocentric.client.services.BlipClientServiceAsync;
import net.thellium.blipocentric.client.utils.Base64Coder;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Blip_o_centric implements EntryPoint {
	BlipClientServiceAsync client = GWT.create(BlipClientService.class);
	public void onModuleLoad() {
		final Label statusHtml =  new Label("Status",true);

		
		Label hosted = new Label();
		hosted.setText("Hosted "+GWT.isScript());
		RootPanel.get().add(hosted);
		RootPanel.get().add(statusHtml);
		String authHDR = Base64Coder.encode("mlodzianck:kacper123");
		client.getData("users/mlodzianck.json", authHDR,new AsyncCallback<String>() {
			
			@Override
			public void onSuccess(String result) {
				JSONObject obj= (JSONObject) JSONParser.parse(result);
				statusHtml.setText("current_status_path "+obj.get("current_status_path").toString());
			}
			
			@Override
			public void onFailure(Throwable caught) {
				Window.alert(caught.getLocalizedMessage());
				
			}
		});
		
	}
	
}
